local kuangcai = fk.CreateSkill {
  name = "kl__kuangcai",
}


kuangcai:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(kuangcai.name) and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@kl__kuangcai-phase", 5)
  end,
})

kuangcai:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:usedSkillTimes(kuangcai.name, Player.HistoryPhase) > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@kl__kuangcai-phase", 1)
    player:drawCards(1, kuangcai.name)
  end,
})

kuangcai:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    return card and player:usedSkillTimes(kuangcai.name, Player.HistoryPhase) > 0 and player:getMark("@kl__kuangcai-phase") == 0
  end,
})

kuangcai:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player:usedSkillTimes(kuangcai.name, Player.HistoryPhase) > 0
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and player:usedSkillTimes(kuangcai.name, Player.HistoryPhase) > 0
  end,
})

return kuangcai
